package com.hzcx.app.simplechat.ui.group;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.chat.bean.GroupSearchBean;
import com.hzcx.app.simplechat.ui.friend.FriendSortActivity;
import com.hzcx.app.simplechat.ui.home.AddFriendFirstActivity;
import com.hzcx.app.simplechat.util.app.AppHelper;
import com.hzcx.app.simplechat.util.toast.ToastUtils;

import butterknife.OnClick;

public class GroupQuestionFragment extends Fragment {

//    @BindView(R.id.tv_title)
    TextView tvTitle;
//    @BindView(R.id.iv_back)
    ImageView ivBack;
//    @BindView(R.id.iv_title_right)
    ImageView ivTitleRight;
//    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
//    @BindView(R.id.question)
    TextView question;
//    @BindView(R.id.answer)
     EditText answer;

    private GroupSearchBean groupSearchBean;

    @Override
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState
    ) {
        return inflater.inflate(R.layout.fragment_group_question, container, false);
    }

    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tvTitle = view.findViewById(R.id.tv_title);
        tvTitleRight = view.findViewById(R.id.tv_title_right);
        ivBack = view.findViewById(R.id.iv_back);
        question = view.findViewById(R.id.question);
        answer = view.findViewById(R.id.answer);

        tvTitle.setText("加入群聊");
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppHelper.closeSoftKeybord(view, getContext());
                ((AddGroupForSearchActivity)getActivity()).selectFragment(0);
            }
        });
        tvTitleRight.setText("发送");
        tvTitleRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String ans = String.valueOf(((EditText)answer).getText());
                if (ans.isEmpty()) {
                    ToastUtils.show("请输入答案");
                    return;
                }
                AppHelper.closeSoftKeybord(view, getContext());
                ((AddGroupForSearchActivity)getActivity()).applyJoinGroup(ans);
            }
        });

        AddGroupForSearchActivity addGroupForSearchActivity = (AddGroupForSearchActivity)getActivity();
        groupSearchBean = (GroupSearchBean)addGroupForSearchActivity.getIntent().getSerializableExtra(AddGroupForSearchActivity.bean);
        question.setText("问题: " + groupSearchBean.getQuestion1());
    }

}